﻿using System;
using System.Collections.Generic;

using System.Text;
using System.Windows.Controls;
using System.Windows;

namespace Bixas.Tangibilis.Controls
{
    public class TouchTabItem : TabItem, ITouchCursorEvent, ITouchCursorEventThunk, ITouchElement
  {
      #region ITouchCursorEvent Members

      public event System.Windows.RoutedEventHandler TouchCursorDown
      {
          add
          {
              this.AddHandler(TouchCursorEvents.TouchCursorDownEvent, value, false);
          }
          remove
          {
              this.RemoveHandler(TouchCursorEvents.TouchCursorDownEvent, value);
          }
      }

      public event System.Windows.RoutedEventHandler TouchCursorEnter
      {
          add
          {
              this.AddHandler(TouchCursorEvents.TouchCursorEnterEvent, value, false);
          }
          remove
          {
              this.RemoveHandler(TouchCursorEvents.TouchCursorEnterEvent, value);
          }
      }

      public event System.Windows.RoutedEventHandler TouchCursorLeave
      {
          add
          {
              this.AddHandler(TouchCursorEvents.TouchCursorLeaveEvent, value, false);
          }
          remove
          {
              this.RemoveHandler(TouchCursorEvents.TouchCursorLeaveEvent, value);
          }
      }

      public event System.Windows.RoutedEventHandler TouchCursorMove
      {
          add
          {
              this.AddHandler(TouchCursorEvents.TouchCursorMoveEvent, value, false);
          }
          remove
          {
              this.RemoveHandler(TouchCursorEvents.TouchCursorMoveEvent, value);
          }
      }

      public event System.Windows.RoutedEventHandler TouchCursorUp
      {
          add
          {
              this.AddHandler(TouchCursorEvents.TouchCursorUpEvent, value, false);
          }
          remove
          {
              this.RemoveHandler(TouchCursorEvents.TouchCursorUpEvent, value);
          }
      }

      public event System.Windows.RoutedEventHandler TouchCursorPreviewDown
      {
          add
          {
              this.AddHandler(TouchCursorEvents.TouchCursorPreviewDownEvent, value, false);
          }
          remove
          {
              this.RemoveHandler(TouchCursorEvents.TouchCursorPreviewDownEvent, value);
          }
      }

      public event System.Windows.RoutedEventHandler TouchCursorPreviewMove
      {
          add
          {
              this.AddHandler(TouchCursorEvents.TouchCursorPreviewMoveEvent, value, false);
          }
          remove
          {
              this.RemoveHandler(TouchCursorEvents.TouchCursorPreviewMoveEvent, value);
          }
      }

      public event System.Windows.RoutedEventHandler TouchCursorPreviewUp
      {
          add
          {
              this.AddHandler(TouchCursorEvents.TouchCursorPreviewUpEvent, value, false);
          }
          remove
          {
              this.RemoveHandler(TouchCursorEvents.TouchCursorPreviewUpEvent, value);
          }
      }
      #endregion

    private TouchTabItemAdapter _adapter;

    private static readonly DependencyProperty IsTouchCursorOverProperty;
    private static readonly DependencyProperty IsTouchCursorPressedProperty;

    public TouchTabItem()
      : base()
    {
      this._adapter = new TouchTabItemAdapter(this);
       
    }

    static TouchTabItem()
    {
      //FrameworkElement.DefaultStyleKeyProperty.OverrideMetadata(typeof(TouchButton), new FrameworkPropertyMetadata(typeof(TouchButton)));
        TouchTabItem.IsTouchCursorOverProperty = DependencyProperty.Register("IsTouchCursorOver", typeof(bool), typeof(TouchTabItem), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.None, null));
        TouchTabItem.IsTouchCursorPressedProperty = DependencyProperty.Register("IsTouchCursorPressed", typeof(bool), typeof(TouchTabItem), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.None, null));
      
    }

    #region ITouchCursorEventThunk Members

    public void OnTouchCursorDownThunk(object sender, System.Windows.RoutedEventArgs e)
    {
        this._adapter.OnTouchCursorDown(e);
    }

    public void OnTouchCursorEnterThunk(object sender, System.Windows.RoutedEventArgs e)
    {
        this._adapter.OnTouchCursorEnter(e);
    }

    public void OnTouchCursorLeaveThunk(object sender, System.Windows.RoutedEventArgs e)
    {
        this._adapter.OnTouchCursorLeave(e);
    }

    public void OnTouchCursorMoveThunk(object sender, System.Windows.RoutedEventArgs e)
    {
        this._adapter.OnTouchCursorMove(e);
    }

    public void OnTouchCursorUpThunk(object sender, System.Windows.RoutedEventArgs e)
    {
        this._adapter.OnTouchCursorUp(e);
    }

    public void OnTouchCursorPreviewDownThunk(object sender, System.Windows.RoutedEventArgs e)
    {
      this._adapter.OnTouchCursorPreviewDown(sender, e);
    }

    public void OnTouchCursorPreviewMoveThunk(object sender, System.Windows.RoutedEventArgs e)
    {
      this._adapter.OnTouchCursorPreviewMove(sender, e);
    }

    public void OnTouchCursorPreviewUpThunk(object sender, System.Windows.RoutedEventArgs e)
    {
      this._adapter.OnTouchCursorPreviewUp(sender, e);
    }

    #endregion

    

    internal void CrackedWriteFlag(uint flags, bool value)
  {
    Phydeaux.Utilities.Dynamic<UIElement>.Instance.Procedure.Params.CreateDelegate("WriteFlag").Invoke(this,new object[] { flags, value});
      
  }


    #region ITouchElement Members

    bool ITouchElement.IsTouchCursorOver
    {
        get
        {
            return (bool)base.GetValue(IsTouchCursorOverProperty);
        }
        set
        {
            base.SetValue(IsTouchCursorOverProperty, value);
            // this.CrackedWriteFlag(0x2000, value);
        }
    }

    bool ITouchElement.IsTouchCursorPressed
    {
        get
        {
            return (bool)base.GetValue(IsTouchCursorPressedProperty);
        }
        set
        {
            base.SetValue(IsTouchCursorPressedProperty, value);
        }
    }

    #endregion
    
    }
}
